package ObserableModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author
 * @create 2018-10-18 12:51
 **/
public class TeacherSubject implements  Subject {

    //存放观察者的对象
    private List<Observer> observerList = new ArrayList<Observer>();

    @Override
    public void registerObserver(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {

        int i = observerList.indexOf(observer);
        if (i >= 0) {
            observerList.remove(observer);
        }
    }

    @Override
    public void notifyAllObserver(String msg) {

        for (Observer observer : observerList) {
            observer.update(msg);
        }
    }
}
